package spark_class_study.spark_Graph

import org.apache.spark.api.java.JavaSparkContext.fromSparkContext
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx
import org.apache.spark.graphx.{Edge, Graph}

object study01 {
  def main(args: Array[String]): Unit = {

    //  创建图以及图的反转


    val sparkconf=new SparkConf().setAppName("test").setMaster("local[*]")
    val sc=new SparkContext(sparkconf)

    //  用户名字作为顶点
    val users=sc.textFile("hdfs://192.168.40.110:9000/datas/user.txt").map{
      line => val lines=line.split(",")
        (lines(0).toLong,(lines(1),lines(2).toInt))
    }

    val relationships=sc.textFile("hdfs://192.168.40.110:9000/datas/relate.txt").map{
      line => val lines=line.split(",")
        Edge(lines(0).toLong, lines(1).toLong,lines(2).toInt)
    }

    //  构建图形
    val graph=Graph(users,relationships)

    graph.vertices.collect.foreach(println)

    graph.edges.collect.foreach(println)






    sc.close()
  }

}
